﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace szse
{
    class Notice
    {
        private string ticker = "";
        public string Ticker
        {
            get { return ticker; }
            set { ticker = value; }
        }

        private string name = "";
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string start = "";
        public string Start
        {
            get { return start; }
            set { start = value; }
        }

        private string end = "";
        public string End
        {
            get { return end; }
            set { end = value; }
        }

        private string title = "";
        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string reason = "";
        public string Reason
        {
            get { return reason; }
            set { reason = value; }
        }

        private string msg = "";
        public string Msg
        {
            get { return msg; }
            set { msg = value; }
        }

        /*
         * <tr  class='cls-data-tr' bgcolor='WhiteSmoke' height='30px'>
         * <td  class='cls-data-td' style='mso-number-format:\@' align='center' >000017</td>
         * <td  class='cls-data-td'  width='70'  align='center' >*ST中华A</td>
         * <td  class='cls-data-td'  width='135'  align='center' >2011-06-28 开市</td>
         * <td  class='cls-data-td'  width='135'  align='center' >2011-06-29 开市</td>
         * <td  class='cls-data-td'  align='center' >1天       </td>
         * <td  class='cls-data-td'  align='left' >召开股东大会</td>
         * </tr>
        */
        public bool ParseFromLine(string line, string domain)
        {
            string tag1 = "align='center' >";
            string tag2 = "</td>";
            string tag3 = "align='left' >";

            int start = 0;
            int p = 0;
            int q = 0;
            p = line.IndexOf(tag1, start);
            q = line.IndexOf(tag2, p);
            this.ticker = line.Substring(p + tag1.Length, q - (p + tag1.Length));

            start = (q + tag2.Length);
            p = line.IndexOf(tag1, start);
            q = line.IndexOf(tag2, p);
            this.name = line.Substring(p + tag1.Length, q - (p + tag1.Length));

            start = (q + tag2.Length);
            p = line.IndexOf(tag1, start);
            q = line.IndexOf(tag2, p);
            this.start = line.Substring(p + tag1.Length, q - (p + tag1.Length));
            if (this.start.EndsWith("开市"))
            {
                this.start = this.start.Split(new char[] { ' ' })[0];
            }

            start = (q + tag2.Length);
            p = line.IndexOf(tag1, start);
            q = line.IndexOf(tag2, p);
            this.end = line.Substring(p + tag1.Length, q - (p + tag1.Length));
            if(this.end.EndsWith("开市"))
            {
                this.end = this.end.Split(new char[] { ' ' })[0];
            }

            start = (q + tag2.Length);
            p = line.IndexOf(tag1, start);
            q = line.IndexOf(tag2, p);
            this.title = line.Substring(p + tag1.Length, q - (p + tag1.Length)).Trim();

            start = (q + tag2.Length);
            p = line.IndexOf(tag3, start);
            q = line.IndexOf(tag2, p);
            this.reason = line.Substring(p + tag1.Length, q - (p + tag1.Length));

            this.msg = "";


            return true;
        }

        public override bool Equals(object right)
        {
            Notice n = right as Notice;
            return (0 == string.Compare(this.Ticker, n.Ticker) &&
                0 == string.Compare(this.Name, n.Name) &&
                0 == string.Compare(this.Start, n.Start) &&
                0 == string.Compare(this.End, n.End) &&
                0 == string.Compare(this.Title, n.Title) &&
                0 == string.Compare(this.Reason, n.Reason));
        }

        public void print()
        {
            Console.WriteLine(string.Format("{0},{1}, {2}:{3}, ({4}, {5})",
                this.Ticker, this.Name, this.Start, this.End, this.Title, this.Reason));
        }
    }
}

